/**  
* @Title: VideoTeachingServiceImpl.java  
* @Description: TODO(用一句话描述该文件做什么)  
* @author 张鑫
* @phone 17561783855  
* @date 2019年6月22日  
*/
package com.fortune.rainshinesystem.service.impl;

import java.util.List;
import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.fortune.rainshinecommon.base.MsgModel;
import com.fortune.rainshinecommon.enums.ResultCode;
import com.fortune.rainshinecommon.model.system.VideoNewsModel;
import com.fortune.rainshinesystem.mapper.VideoNewsMapper;
import com.fortune.rainshinesystem.service.VideoNewsService;
import com.google.common.collect.Lists;

/**  
* @ClassName: VideoTeachingServiceImpl  
* @Description: TODO(这里用一句话描述这个类的作用)  
* @author 张鑫
* @phone 17561783855
* @date 2019年6月22日  
*    
*/
@Service
public class VideoNewsServiceImpl implements VideoNewsService {
    private static final Logger logger = LoggerFactory.getLogger(VideoNewsServiceImpl.class);
    
    @Autowired
    private VideoNewsMapper mapper;

	@Override
	@Transactional
	public MsgModel createShop(VideoNewsModel model) {
		model.setCreateId(model.getUser().getUserId());
		model.setUpdateId(model.getUser().getUserId());
		int res = mapper.insert(model);
        if (res > 0) {
            return new MsgModel("保存视频成功！", ResultCode.SUCCESS);
        } else {
            return new MsgModel("保存视频失败！", ResultCode.FAILURE);
        }
	}

	@Override
	public MsgModel list() {
		List<VideoNewsModel> list = Optional.ofNullable(mapper.selectList(
                new EntityWrapper<VideoNewsModel>().orderBy("create_time", false))).orElse(Lists.newArrayList());
		return new MsgModel(ResultCode.SUCCESS,list);
	}

	@Override
	public MsgModel delete(VideoNewsModel model) {
        try {
            boolean rs = mapper.deleteById(model.getId()) > 0;
            if (rs) {
                return new MsgModel("删除成功！", ResultCode.SUCCESS);
            } else {
                return new MsgModel("删除失败！", ResultCode.FAILURE);
            }
        } catch (Exception e) {
            logger.error("delProduct ===>" + e.getMessage());
            return new MsgModel("删除产品失败！", ResultCode.FAILURE);
        }
	}
}
